<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_reload = function() {
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };

	var grid_reload_filter = function(){
		var bulan_dari = $('#bulan_dari').val();
		var bulan_sampai = $('#bulan_sampai').val();
		var tahun = $('#tahun').val();
		var status_bayar = $('#status_bayar').val();
        if( status_bayar=='all'){
            grid_reload();
        } else {0
		  $('#datagrid').datagrid('reload', {'set':'filter','bulan_dari':bulan_dari,'bulan_sampai':bulan_sampai,'status_bayar':status_bayar,'tahun':tahun});			 
        }
	};

    $(document).ready(function() {
       // Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:480,
			pagination:true,
			//singleSelect:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'no_tagihan_sewa', title : 'No Tagihan Sewa', width:100, sortable:true, rowspan:2},
				{ field : 'tanggal_bayar', title : 'Tanggal Pembayaran', width:130, sortable:true, rowspan:2},
                { field : 'no_bukti_pembayaran', title : 'No Pembayaran', width:130, sortable:true, rowspan:2},
				{ field : 'periode_pembayaran', title : 'Periode Pembayaran', width:130, sortable:true, rowspan:2},
				{ field : 'nama_tenant', title : 'Nama Tenant', width:130, sortable:true, rowspan:2},
				{ field : 'no_toko', title : 'No Toko', width:100, sortable:true, rowspan:2},
				{ field : 'jenis_usaha', title : 'Jenis Usaha', width:100, sortable:true, rowspan:2},
				{ field : 'lokasi_tempat', title : 'Lokasi Tempat', width: 250, sortable:true, rowspan:2},
				{ field : 'harga_sewa', title : 'Harga Sewa', width:100, sortable:true, rowspan:2},
				{ field : 'status_bayar', title : 'Status Bayar', width:100, sortable:true, rowspan:2},
				
			]]
		});
        

        // Setup Form
		$('#form_filter').setupForm([
			{ name: 'bulan_dari', type: 'text', size: 'short'},
			{ name: 'bulan_sampai', type: 'text', size: 'short'},
			{ name: 'tahun', type: 'text', size: 'short'},
			{ name: 'status_bayar', type: 'text', size: 'medium'},
			{ name: 'status_bayar_b', type: 'text', size: 'medium'},
		]);



        // Set Action Button
        var buttons = [ 
                        // ----- >> Edit Button
					    { label: 'Print Semua', icon: 'print', onclick: function() {
                                var status_bayar = $('#status_bayar').val();
                                window.location = gs_path + '/pro_print_excel_new/tagihan_sewa_all/?status_bayar='+status_bayar;
					     }},
					    { label: 'Print Satuan', icon: 'print', onclick: function() {
								var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								window.location = gs_path + '/pro_print_excel_new/tagihan_sewa_satuan/?no_tagihan_sewa='+urlencode(oSel.no_tagihan_sewa);
					        } 

					    }},
                        { label: 'Print PDF', icon: 'print', onclick: function() {
                                var oSel = $('#datagrid').datagrid('getSelected');
                            if (oSel == null) {
                                $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
                            } else {
                                window.open(gs_path+'/'+controller+'/cetak/?no_tagihan_sewa='+urlencode(oSel.no_tagihan_sewa), 'myWin', 'height=500,width=700,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
                            } 

                        }},
                        { label: 'Print Total Pendapatan Sewa', icon: 'print', onclick: function() {
                            var bulan_dari = $('#bulan_dari').val();
                            var bulan_sampai = $('#bulan_sampai').val();
                            var tahun = $('#tahun').val();
                            if ($('#bulan_dari').val()== null &&  $('#bulan_sampai').val()== null) {
                                alert('Silahkan Pilih Range Periode Pembayaran!'); 
                            } else {
                                window.location = gs_path + '/pro_print_excel_new/total_pendapatan_sewa/?bulan_dari='+bulan_dari+'/&& bulan_sampai='+bulan_sampai+'/&& tahun='+tahun;
                            } 
                        }},
					    ];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
    });
//--><!]]></script>

    
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<fieldset>
                <legend>Kolom Range Filter </legend>
                <table class="tb_form" style="margin-bottom:0px">
                    <tr>
                        <td style="width:120px">Periode Tagihan</td> Dari Bulan
                        <td ><select id="bulan_dari" name="bulan_dari">
                            <option value="01">Januari</option>
                            <option value="02">Februari</option>
                            <option value="03">Maret</option>
                            <option value="04">April</option>
                            <option value="05">Mei</option>
                            <option value="06">Juni</option>
                            <option value="07">Juli</option>
                            <option value="08">Agustus</option>
                            <option value="09">September</option>
                            <option value="10">Oktober</option>
                            <option value="11">November</option>
                            <option value="12">Desember</option>
                        </select> 
                         S/D 
                        <select id="bulan_sampai" name="bulan_sampai">
                            <option value="01">Januari</option>
                            <option value="02">Februari</option>
                            <option value="03">Maret</option>
                            <option value="04">April</option>
                            <option value="05">Mei</option>
                            <option value="06">Juni</option>
                            <option value="07">Juli</option>
                            <option value="08">Agustus</option>
                            <option value="09">September</option>
                            <option value="10">Oktober</option>
                            <option value="11">November</option>
                            <option value="12">Desember</option>
                        </select> Tahun 
                        <?php
                        $now = date('Y');
                        $pastYear = $now - 10; 
                        echo "<select id='tahun' name='tahun' >";
                        for ($a=$pastYear;$a<=$now;$a++)
                        {
                            echo"<option value='".$a."''>".$a."</option>";  
                        }
                        echo"</select>";
                        ?>
                        <td style="width:70px">Status Bayar</td>
                        <td colspan="5"><select id="status_bayar" name="status_bayar">
                            <option value="all">All</option>
                            <option value="Belum Bayar">Belum Bayar</option>
                            <option value="Sudah Bayar">Sudah Bayar</option>
                        </select>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload_filter(); return false;">Filter Bersarkan Peroide Tagihian</a>
                    </td>
                </td>
                <!--<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload_filter(); return false;">Filter</a>-->
            </td>
        </tr>
        </table>   
    </fieldset>
            
            <table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td class="label" width="100">Keyword (All Search)</td>
                <td colspan = "3"><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-blank-file" onclick="$('#fm_search').resetForm(); return false;">Reset</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>

